package model.registro;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class RegistroOrdAparicion extends Registro implements Comparable<RegistroOrdAparicion>{
	
	private int nroAparicion;
	private int offsetDoc;
	private int CantTerminosDoc;
	private float repeticiones;
	private float pesoGlobal;
	
	public RegistroOrdAparicion(int nroAparicion, int offsetDoc, int CantTerminosDoc, float repeticiones, float pesoGlobal)
	{
		this.nroAparicion = nroAparicion;
		this.offsetDoc = offsetDoc;	
		this.CantTerminosDoc = CantTerminosDoc;
		this.repeticiones = repeticiones;
		this.pesoGlobal = pesoGlobal;
	}
	
	public RegistroOrdAparicion(){
		
	}
		
	public int getNroAparicion() {
		return nroAparicion;
	}
	public int getOffsetDoc() {
		return offsetDoc;
	}
	public int getCantTerminosDoc() {
		return CantTerminosDoc;
	}
	public float getRepeticiones() {
		return repeticiones;
	}
	public void setCantTerminosDoc(int cantTerminosDoc) {
		CantTerminosDoc = cantTerminosDoc;
	}
	public void setRepeticiones(float repeticiones) {
		this.repeticiones = repeticiones;
	}
	public int compareTo(RegistroOrdAparicion o) {
		return (this.nroAparicion < o.getNroAparicion() ? -1 :
            (this.nroAparicion > o.getNroAparicion()) ? 1 : 
            (this.repeticiones > o.getRepeticiones())? -1 :
            (this.repeticiones < o.getRepeticiones()) ? 1 : 0);
	}
	
	public boolean equals(RegistroOrdAparicion o){
		if ((this.nroAparicion==o.getNroAparicion()) &&
				(this.offsetDoc == o.getOffsetDoc()))
				return true;
			else return false;
	}

	public float getPesoGlobal() {
		return pesoGlobal;
	}

	public void setPesoGlobal(float pesoGlobal) {
		this.pesoGlobal = pesoGlobal;
	}
	
	public byte[] convertirRegistroABytes() throws IOException {

		ByteArrayOutputStream bytesRegistro = new ByteArrayOutputStream();
		DataOutputStream output = new DataOutputStream(bytesRegistro);
		
		output.writeInt(this.nroAparicion);
		output.writeInt(this.offsetDoc);
		output.writeInt(this.CantTerminosDoc);
		output.writeFloat(this.repeticiones);
		output.writeFloat(this.pesoGlobal);

		return bytesRegistro.toByteArray();

	}

	public void convertirBytesARegistro(byte[] xInput) throws IOException {

		ByteArrayInputStream bytesRegistro = new ByteArrayInputStream(xInput);
		DataInputStream input = new DataInputStream(bytesRegistro);

		this.nroAparicion = input.readInt();
		this.offsetDoc = input.readInt();
		setCantTerminosDoc(input.readInt());
		setRepeticiones(input.readFloat());
		setPesoGlobal(input.readFloat());

	}

	public int getTamanioRegistro() {
		return 3 *ConversionesTiposDatos.sizeOfInt() + 2*Float.SIZE/8;
	}

}
